package com.xiangban.volunteer_platform.controller;

import com.xiangban.volunteer_platform.dao.WorkTypeMapper;
import com.xiangban.volunteer_platform.entity.WorkType;
import com.xiangban.volunteer_platform.service.WorkTypeService;
import com.xiangban.volunteer_platform.utils.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Mr. MaYaYun
 * @Data 2021/1/26 14:10
 */
@RestController
@Api(tags = "任务类型控制器")
@RequestMapping("/api/work_type")
public class WorkTypeController {

    @Autowired
    private WorkTypeService workTypeService;

    @PostMapping("/addWorkType")
    @ApiOperation("任务类型添加")
    public JsonData addWorkType(@RequestBody WorkType workType){
        workTypeService.save(workType);
        return JsonData.buildSuccess(workType.getId());
    }

    @PostMapping("/delWorkType")
    @ApiOperation("任务类型删除")
    public JsonData delWorkType(@RequestBody WorkType workType){
        workTypeService.del(workType);
        return JsonData.buildSuccess("删除成功");
    }

    @PostMapping("/updateWorkType")
    @ApiOperation("任务类型修改")
    public JsonData updateWorkType(@RequestBody WorkType workType){
        workTypeService.update(workType);
        return JsonData.buildSuccess("修改成功");
    }


    @GetMapping("/getAllWorkType")
    @ApiOperation("获取所有任务类型列表")
    public JsonData getAllWorkType(){

        return JsonData.buildSuccess(workTypeService.getAll());
    }

    @PostMapping("/getWorkTypeById")
    @ApiOperation("根据id获取任务类型")
    public JsonData getWorkTypeById(@RequestBody WorkType workType){
       return JsonData.buildSuccess(workTypeService.getWorkType(workType));
    }
}
